package com.zm.devmag.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/2/25.
 */
public class CalendarUtil {
  
    public static String getCurr(String pattern){
       Date date = new Date();
       DateFormat df = new SimpleDateFormat(pattern);
       return df.format(date);
    }
    
    public static Date parseDate(String date,String pattern ) throws ParseException{
    	DateFormat df = new SimpleDateFormat(pattern);
    	return df.parse(date);
    }
    
    public static String getDateStr(Date date,String pattern){
        DateFormat df = new SimpleDateFormat(pattern);
        return df.format(date);
     }
    public static Date  getCurrentDayStartTime(){
    	Calendar calendar = Calendar.getInstance();
    	calendar.set(Calendar.HOUR_OF_DAY, 0);
    	calendar.set(Calendar.MINUTE, 0);
    	calendar.set(Calendar.SECOND, 0);
    	return calendar.getTime();
    }
    public  static Date getCurrentWeekStartTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_WEEK, 2);
    	calendar.set(Calendar.HOUR_OF_DAY, 0);
    	calendar.set(Calendar.MINUTE, 0);
    	calendar.set(Calendar.SECOND, 0);
      
        return calendar.getTime();
    } 
    public  static Date getCurrentMonthStartTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, 1);
    	calendar.set(Calendar.HOUR_OF_DAY, 0);
    	calendar.set(Calendar.MINUTE, 0);
    	calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    } 
    
    public  static Date getCurrentYearStartTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
    	calendar.set(Calendar.HOUR_OF_DAY, 0);
    	calendar.set(Calendar.MINUTE, 0);
    	calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    } 
    
    public static Date getOneYearAgo(){
    	Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -11);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
    	calendar.set(Calendar.HOUR_OF_DAY, 0);
    	calendar.set(Calendar.MINUTE, 0);
    	calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    }
      
    
    public static Date getOneMonthAgo(){
    	Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        return calendar.getTime();
    }
    
    public static Date getOneDayAgo(){
    	Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -1);
     	calendar.set(Calendar.HOUR_OF_DAY, 0);
     	calendar.set(Calendar.MINUTE, 0);
     	calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    }
    
    public static Date getTodayBegin(){
    	Calendar calendar = Calendar.getInstance();
     	calendar.set(Calendar.HOUR_OF_DAY, 0);
     	calendar.set(Calendar.MINUTE, 0);
     	calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    }

	public static Date getTimeBeforeMonth(Date then,int i) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(then);
		calendar.add(Calendar.MONTH, i);
		return calendar.getTime();
	}
	
	public static Date getSometimeOneYearAgo(Date then){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(then);
		calendar.add(Calendar.MONTH, -11);
		return calendar.getTime();
	}

	public static Date getHoursAgo(int i) {
		// TODO Auto-generated method stub
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.HOUR_OF_DAY, -i);
		return calendar.getTime();
	}
}
